﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="TwiML" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Response" type="ResponseType" />
  <xs:complexType name="ResponseType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="Say" type="SayVerb" />
      <xs:element name="Play" type="PlayVerb" />
      <xs:element name="Gather" type="GatherVerb" />
      <xs:element name="Record" type="RecordVerb" />
      <xs:element name="Dial" type="DialVerb" />
      <xs:element name="Redirect" type="RedirectVerb" />
      <xs:element name="Pause" type="PauseVerb" />
      <xs:element name="Hangup" type="HangupVerb" />
    </xs:choice>
  </xs:complexType>
  <xs:complexType name="SayVerb">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="voice" type="VoiceValues" use="optional"/>
        <xs:attribute name="language" type="LanguageValues" use="optional"/>
        <xs:attribute name="loop" type="xs:unsignedInt" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:simpleType name="VoiceValues">
    <xs:restriction base="xs:string">
      <xs:enumeration value="man"/>
      <xs:enumeration value="woman"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="LanguageValues">
    <xs:restriction base="xs:string">
      <xs:enumeration value="en"/>
      <xs:enumeration value="es"/>
      <xs:enumeration value="fr"/>
      <xs:enumeration value="de"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="PlayVerb">
    <xs:simpleContent>
      <xs:extension base="xs:anyURI">
        <xs:attribute name="loop" type="xs:unsignedInt" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:complexType name="GatherVerb">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="Say" type="SayVerb" minOccurs="0"/>
      <xs:element name="Play" type="PlayVerb" minOccurs="0"/>
      <xs:element name="Pause" type="PauseVerb" minOccurs="0"/>
    </xs:choice>
    <xs:attributeGroup ref="ActionMethodTimeout"/>
    <xs:attribute name="finishOnKey" type="GatherKeyValues" use="optional"/>
    <xs:attribute name="numDigits" type="IntegerGreaterThanOne" use="optional"/>
  </xs:complexType>
  <xs:attributeGroup name="ActionMethodTimeout">
    <xs:attribute name="action" type="xs:anyURI" use="optional"/>
    <xs:attribute name="method" type="MethodValues" use="optional"/>
    <xs:attribute name="timeout" type="xs:unsignedInt" use="optional"/>
  </xs:attributeGroup>
  <xs:simpleType name="MethodValues">
    <xs:restriction base="xs:string">
      <xs:enumeration value="GET"/>
      <xs:enumeration value="POST"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="GatherKeyValues">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9,#,*]"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="IntegerGreaterThanOne">
    <xs:restriction base="xs:unsignedInt">
      <xs:minInclusive value="1"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="RecordVerb">
    <xs:attributeGroup ref="ActionMethodTimeout"/>
    <xs:attribute name="finishOnKey" type="RecordKeyValues" use="optional"/>
    <xs:attribute name="maxLength" type="IntegerGreaterThanOne" use="optional"/>
    <xs:attribute name="transcribe" type="xs:boolean" use="optional"/>
    <xs:attribute name="transcribeCallback" type="xs:anyURI" use="optional"/>
  </xs:complexType>
  <xs:simpleType name="RecordKeyValues">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9,#,*]+"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="DialVerb" mixed="true">
    <xs:choice>
      <xs:element name="Number" type="NumberNoun" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="Conference" type="ConferenceNoun" minOccurs="0" maxOccurs="1"/>
    </xs:choice>
    <xs:attributeGroup ref="ActionMethodTimeout"/>
    <xs:attribute name="hangupOnStar" type="xs:boolean" use="optional"/>
    <xs:attribute name="timeLimit" type="xs:unsignedInt" use="optional"/>
    <xs:attribute name="callerId" type="xs:string" use="optional"/>
  </xs:complexType>
  <xs:complexType name="NumberNoun">
    <xs:attribute name="sendDigits" type="SendDigitsValues" use="optional"/>
    <xs:attribute name="url" type="xs:anyURI" use="optional"/>
  </xs:complexType>
  <xs:simpleType name="SendDigitsValues">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9,w]+"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="ConferenceNoun">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="muted" type="xs:boolean" use="optional"/>
        <xs:attribute name="beep" type="xs:boolean" use="optional"/>
        <xs:attribute name="startConferenceOnEnter" type="xs:boolean" use="optional"/>
        <xs:attribute name="endConferenceOnExit" type="xs:boolean" use="optional"/>
        <xs:attribute name="waitUrl" type="xs:anyURI" use="optional" />
        <xs:attribute name="waitMethod" type="MethodValues" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:complexType name="RedirectVerb">
    <xs:simpleContent>
      <xs:extension base="xs:anyURI">
        <xs:attribute name="method" type="MethodValues" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:complexType name="PauseVerb">
    <xs:attribute name="length" type="xs:positiveInteger" use="optional"/>
  </xs:complexType>
  <xs:complexType name="HangupVerb"/>
</xs:schema>
